using System;
using System.Web.Mvc;
using System.Web.Routing;
using AspNetMvc.Providers;
using AspNetMvc.Services.Authentication;
using AspNetMvc.Services.Events;
using AspNetMvc.Services.Events.Interfaces;
using Infrastructure.Events;
using Infrastructure.Events.Interfaces;
using Infrastructure.GeoLabels;
using Infrastructure.GeoLabels.Interfaces;
using Infrastructure.IP;
using Infrastructure.IP.Interfaces;
using Infrastructure.Lgd;
using Infrastructure.Lgd.Interfaces;
using Microsoft.Practices.Unity;
using UsersProvider.Repositories;
using UsersProvider.Repositories.RelationalRepositories;
using UsersProvider.Repositories.RelationalRepositories.Interfaces;
using VirtuosoDal.Repositories.RdfRepositories.Events;
using VirtuosoDal.Repositories.RdfRepositories.GeoNames;
using VirtuosoDal.Repositories.RdfRepositories.Interfaces.Events;
using VirtuosoDal.Repositories.RdfRepositories.Interfaces.GeoNames;
using VirtuosoDal.Repositories.RdfRepositories.Interfaces.Lgd;
using VirtuosoDal.Repositories.RdfRepositories.Interfaces.VirtuosoCore;
using VirtuosoDal.Repositories.RdfRepositories.Lgd;
using VirtuosoDal.Repositories.RdfRepositories.VirtuosoCore;

namespace AspNetMvc.MvcFrameworkUtils
{
   public class UnityControllerFactory : DefaultControllerFactory
   {
      private readonly IUnityContainer _unityContainer;

      public UnityControllerFactory()
      {
         _unityContainer = new UnityContainer();

         //_unityContainer.RegisterType<AccountController>("account");
         //_unityContainer.RegisterType<EventController>("event");
         //_unityContainer.RegisterType<EventCrudController>("eventcrud");
         //_unityContainer.RegisterType<GeneralController>("general");
         //_unityContainer.RegisterType<GeoLabelsController>("geolabels");
         //_unityContainer.RegisterType<LgdController>("lgd");
         //_unityContainer.RegisterType<SearchController>("search");

         _unityContainer.RegisterType<IOpenIdUserInfo, OpenIdUserInfo>();
         _unityContainer.RegisterType<OpenIdMembershipProvider, UsersMembershipProvider>();

         _unityContainer.RegisterType<IFormsAuthentication, FormsAuthenticationService>();
         _unityContainer.RegisterType<IMembershipService, AccountMembershipService>();

         _unityContainer.RegisterType<IEventDatesPostParser, EventDatesPostParser>();
         _unityContainer.RegisterType<IEventHoursListGenerator, EventHoursListGenerator>();
         _unityContainer.RegisterType<IEventHoursListService, EventHoursListService>();
         _unityContainer.RegisterType<IEventMinutesListGenerator, EventMinutesListGenerator>();
         _unityContainer.RegisterType<IEventMinutesListService, EventMinutesListService>();
         _unityContainer.RegisterType<IEventPostParser, EventPostParser>();

         _unityContainer.RegisterType<IEventCrudService, EventCrudService>();
         _unityContainer.RegisterType<IEventPropertyDescriptionManager, EventPropertyDescriptionManager>();
         _unityContainer.RegisterType<IEventsOntologyClassesService, EventsOntologyClassesService>();
         _unityContainer.RegisterType<IEventsOntologyClassesTreeBuilder, EventsOntologyClassesTreeBuilder>();

         _unityContainer.RegisterType<IGeoLabelsAdditionService, GeoLabelsAdditionService>();

         _unityContainer.RegisterType<IIpToCultureInfoConverter, IpToCultureInfoConverter>();
         _unityContainer.RegisterType<IIpToNumberConverter, IIpToNumberConverter>();

         _unityContainer.RegisterType<ILgdTreeBuilder, LgdTreeBuilder>();
         _unityContainer.RegisterType<ILgdTreeFilter, LgdTreeFilter>();
         _unityContainer.RegisterType<ILgdTreeFilteringService, LgdTreeFilteringService>();

         _unityContainer.RegisterType<IClearRelationalDataRepository, ClearRelationalDataRepository>();
         _unityContainer.RegisterType<ICountryCodesRepository, CountryCodesRepository>();
         _unityContainer.RegisterType<IEventCommentsRepository, EventCommentsRepository>();
         _unityContainer.RegisterType<IUsersRepository, UsersRepository>();

         _unityContainer.RegisterType<IEventsContentRepository, EventsContentRepository>();
         _unityContainer.RegisterType<IEventsOntologyRepository, EventsOntologyRepository>();
         _unityContainer.RegisterType<IGeoLabelsRepository, GeoLabelsRepository>();

         _unityContainer.RegisterType<IGeoNamesRepository, GeoNamesRepository>();

         _unityContainer.RegisterType<ILgdContentRepository, LgdContentRepository>();
         _unityContainer.RegisterType<ILgdSchemaRepository, LgdSchemaRepository>();

         _unityContainer.RegisterType<IFullTextSearchRepository, FullTextSearchRepository>();
         _unityContainer.RegisterType<IGraphRepository, GraphRepository>();
         _unityContainer.RegisterType<IRuleSetsRepository, RuleSetsRepository>();
         _unityContainer.RegisterType<ISequenceRepository, SequenceRepository>();
      }

      protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
      {
         if (controllerType == null)
            return base.GetControllerInstance(requestContext, controllerType);

         return (IController)_unityContainer.Resolve(controllerType);
      }
   }
}